import debounce from "throttle-debounce/debounce"

export default (doc, win) => {
  const designWidth = 1280;
  const designHeight = 800;
  const el = doc.documentElement;
  const resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize'
  const setSize = function () {
    let w = el.clientWidth;
    const dpr = win.devicePixelRatio || 1;
    if (!w) return;
    w = w > designWidth ? designWidth : w;
    w = w < 320 ? 320 : w;

    el.style.fontSize = ((w * 100) / (designWidth)).toFixed(3) + 'px';
  };
  if (!doc.addEventListener) return;
  let call = debounce(400, setSize.bind(this));
  call();
  win.addEventListener(resizeEvt, call, false);
  doc.addEventListener('DOMContentLoaded', call, false);
}

/*
pc    任意      （缩放，拉伸的时候，比例不变，大小会变）

ipad  618 1.75 = 1081.5
phone 360 3    = 1080
*/